﻿using CustomerScoreManagement.Api.Models;
using CustomerScoreManagement.Api.Services;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace CustomerScoreManagement.Api.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class LeaderboardController : ControllerBase
    {
        private readonly LeaderboardService _leaderboardService;

        public LeaderboardController(LeaderboardService leaderboardService)
        {
            _leaderboardService = leaderboardService;
        }


        [HttpPost("customer/{customerid}/score/{score}")]
        public ActionResult<decimal> UpdateScore(long customerid, decimal score)
        {
            var updatedScore = _leaderboardService.UpdateScore(customerid, score);
            return Ok(updatedScore);
        }

        [HttpGet("leaderboard")]
        public ActionResult<List<Customer>> GetLeaderboard(int start, int end)
        {
            var leaderboard = _leaderboardService.GetLeaderboard(start, end);
            return Ok(leaderboard);
        }

        [HttpGet("leaderboard/{customerid}")]
        public ActionResult<List<Customer>> GetNeighbors(long customerid, int high = 0, int low = 0)
        {
            var neighbors = _leaderboardService.GetNeighbors(customerid, high, low);
            return Ok(neighbors);
        }

    }
}
